package com.springboot.listener;

import com.springboot.event.LoginEvent;
import com.springboot.event.LoginExitEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class MyListener implements SmartApplicationListener {
    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return LoginEvent.class.isAssignableFrom(eventType) || LoginExitEvent.class.isAssignableFrom(eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
      if(event instanceof LoginEvent){
          System.out.println("MyListener 登录事件....");
      }
      if(event instanceof LoginExitEvent){
          System.out.println("MyListener 退出事件....");

      }
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
